package nickthissen.iracing.activities;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Window;

import nickthissen.iracing.common.DataLoader;
import nickthissen.iracing.common.Error;
import nickthissen.iracing.common.Task;
import nickthissen.iracing.common.WebViewUtil;
import nickthissen.iracing.datamodels.Result;
import nickthissen.iracing.iracingforum2.R;
import nickthissen.iracing.networking.Networking;

/**
 * Created by nthissen on 04/06/13.
 */
public class WebActivity extends SherlockActivity
{
    private static final String URL = "URL";
    private static final String TITLE = "TITLE";

    private String url;
    private WebView webview;
    private ProgressDialog dialog;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        SherlockUtils.setNotificationBar(this);
        requestWindowFeature(Window.FEATURE_PROGRESS);

        setContentView(R.layout.web);

        webview = (WebView) this.findViewById(R.id.web);
        webview.getSettings().setSupportZoom(true);

        WebViewUtil.syncCookies(webview);
        webview.setWebChromeClient(new WebChromeClient()
        {
            @Override
            public void onProgressChanged(WebView view, int newProgress)
            {
                setSupportProgress(newProgress * 100);
                super.onProgressChanged(view, newProgress);
            }
        });

        Bundle extras = savedInstanceState;
        if (extras == null)
        {
            Intent i = this.getIntent();
            extras = i.getExtras();
        }
        url = extras.getString(URL);
        String title = extras.getString(TITLE);

        this.getSupportActionBar().setTitle(title);

        webview.loadUrl(url);
    }

    public static Intent getIntent(Context context, String url, String title)
    {
        Intent i = new Intent(context, WebActivity.class);
        i.putExtra(URL, url);
        return i;
    }
}
